// 分页相关固定代码
import Pagination from '@/modules/CST/components/Pagination'
import elDragDialog from '@/modules/CST/directive/el-dragDialog'
import { parseTime } from '@/modules/CST/utils/index'
import { CONSENT_GET_CURRENT_VERSION} from "_SERVICES/api";
import { getStorage, setStorage } from "UTILS/util";

export default {
  components:{
    Pagination
  },
  directives: { elDragDialog },
 
  data() {
    return {
      tableHeight: 250,
      listLoading: false,
      downloadLoading: false,
      listQuery: {
        start: 1, // 第几条（从1开始）
        pageSize: 20, // 每页条数
        orderby: "", // 排序
        totalNum: 0, // 总条数
      },
      tableData: [],
      downloadData: []
    }
  },
  activated(){
    //解决keep-alive导致表格高度不准问题
    if(this.$refs.elTable){
      this.$refs.elTable.doLayout();
    }
  },
  methods: {
    // getTableHeight(){
    //   this.$nextTick(()=>{
    //     this.tableHeight = this.mixin_getTableHeight();
    //     window.onresize = v => {
    //       this.tableHeight = this.mixin_getTableHeight();
    //     }
    //   });
    // },
    //刷卡回写brbh到输入栏
    setBrbh(list) {
    
      let ybk= "";
      let lk = "";
      let dzjkm = ""
      if (list && list.length) {
        for (let i = 0; i <= list.length - 1; i++) {
          let item = list[i];
        
          if(item.KLX == "医保") {
            ybk = item.BRBH;
          }
          if(item.KLX == "自费绿卡") {
            lk = item.BRBH;
          }
          if(item.KLX == "电子健康码") {
            dzjkm = item.BRBH;
          }
        }
        this.formInline.BRBH = ybk || lk || dzjkm;
      }
    },
    //版本控制
    CONSENT_GET_CURRENT_VERSION(){
      CONSENT_GET_CURRENT_VERSION({}).then((res)=>{
        if(res.data && res.data.length) {
          var version = res.data[0].BZ;
          if(version != getStorage("CST_VERSION")){
            setStorage({
              name:"CST_VERSION",
              value:version
            });
            location.reload(true);
          }else{
            console.log("未更新版本")
          }
        }
       
      })
    },
    search() {
      this.listQuery.start = 1;
      this.getList();
    },
    //获取页面参数
    /*
     * type=0表示从0开始 兼容后端数据库不同类型
     * 不传表示从1开始
     */
    getParams(type){
      let params =  {
        start: (this.listQuery.start - 1) * this.listQuery.pageSize + 1,
        pageSize: this.listQuery.pageSize,
        orderby: this.listQuery.orderby
      }
      if(type == 0){
        params.start = params.start-1;
      }
      // console.log('getParam',type,params)
      return params;
    },
    //排序
    sortChange(info){
      let type = null;
      if(info.order == "ascending"){
        type = 1;
      }else if(info.order == "descending"){
        type = 0;
      }
      if(!info.prop){
        this.listQuery.orderby = "";
      }else{
        this.listQuery.orderby = [{
          Name: info.prop,
          Type: type
        }];
      }
      this.search();
    },
    //清除
    resetForm(name) {
      this.$refs[name].resetFields();
      this.search();
    },
    formatJson(filterVal, jsonData) {
      return jsonData.map(v => filterVal.map(j => {
        if (j === 'timestamp') {
          return parseTime(v[j])
        } else {
          return v[j]
        }
      }))
    },
  }
};
